// -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	RefValue.cs
//  Developer:	Igor Solomatov
//  Created:	03.03.2013
// 
// -------------------- iSharePoint -------------------- //

using System;

namespace Smart
{
	public class RefValue<TValueType> : IEquatable<TValueType>, IEquatable<RefValue<TValueType>>
	{
		public TValueType Value;

		public RefValue()
		{
		}

		public RefValue(TValueType value)
		{
			Value = value;
		}

		public static implicit operator TValueType(RefValue<TValueType> value)
		{
			return value.Value;
		}

		public static implicit operator RefValue<TValueType>(TValueType value)
		{
			return new RefValue<TValueType>(value);
		}

		public override int GetHashCode()
		{
			return Value.GetHashCode();
		}

		public bool Equals(TValueType other)
		{
			return Value.Equals(other);
		}

		public bool Equals(RefValue<TValueType> other)
		{
			return Value.Equals(other.Value);
		}

		public override bool Equals(object obj)
		{
			var other = obj as RefValue<TValueType>;
			return Value.Equals(other != null ? other.Value : obj);
		}
	}
}